<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<script type="text/javascript" src="js/jquery-1.9.0rc1.js" ></script>
	<script type="text/javascript">
		onload = function(){
			var btn = document.getElementById("createLink");
			var count = 1;
//			
//			document.body.onclick = function(e){
//				var e = e || event;
//				var _this = e.target;
//				if(_this.tagName == "A") {
//					e.preventDefault();
//					alert(_this.innerText);
//				}
//			}
			//该方法用来替代live和delegate
			$("div").on("click","a",function(event){
				event.preventDefault();
				alert($(this).text());
			})
			/*$("div").delegate("a","click",function(event){
				event.preventDefault();
				alert($(this).text());
			});*/
			
			btn.onclick = function(){
				var link = document.createElement("a");
				link.innerText = "这是动态生成的一个超链接"+count++;
				link.href = "www.google.com";
				document.getElementById("parentlink").appendChild(link);
				var br = document.createElement("br");
				document.getElementById("parentlink").appendChild(br);
				
				/*link.onclick = function(e){
					var e = e || event;
					e.preventDefault();
					alert(this.innerText);
				}*/
			}
		}
	</script>
	<body>
		<button id="createLink">按下一次生成一个超链接</button>
		<div id="parentlink">
			
		</div>
	</body>
</html>
